﻿//****************************************************************************
// Copyright (c) Microsoft Corporation. All rights reserved.
//****************************************************************************
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.FxCop.Sdk;

namespace Microsoft.FxCop.Rules.ASP.MVC.Security
{
    internal sealed class PageHelper
    {

        private PageHelper()
        {
        }

        public static bool IsPageInitMethod(Method method)
        {
            if (method.Name.Name != "Page_Init")
                return false;

            if (method.ReturnType != FrameworkTypes.Void)
                return false;

            if (method.Parameters.Count != 2)
                return false;

            if (method.Parameters[0].Type != FrameworkTypes.Object)
                return false;

            if (method.Parameters[1].Type != FrameworkTypes.EventArgs)
                return false;

            return true;
        }

        public static bool IsOnInitMethod(Method method)
        {
            if (method.Name.Name != "OnInit")
                return false;

            if (method.ReturnType != FrameworkTypes.Void)
                return false;

            if (method.Parameters.Count != 1)
                return false;

            if (method.Parameters[0].Type != FrameworkTypes.EventArgs)
                return false;

            return true;
        }

        public static bool IsPageLoadMethod(Method method)
        {
            if (method.Name.Name != "Page_Load")
                return false;

            if (method.ReturnType != FrameworkTypes.Void)
                return false;

            if (method.Parameters.Count != 2)
                return false;

            if (method.Parameters[0].Type != FrameworkTypes.Object)
                return false;

            if (method.Parameters[1].Type != FrameworkTypes.EventArgs)
                return false;

            return true;
        }

        public static bool IsFrameworkInitializeMethod(Method method)
        {
            if (method.Name.Name != "FrameworkInitialize")
                return false;

            if (method.ReturnType != FrameworkTypes.Void)
                return false;

            if (method.Parameters.Count != 0)
                return false;

            return true;
        }

        public static bool IsBuildControlTreeMethod(Method method)
        {
            if (method.Name.Name != "__BuildControlTree")
                return false;

            if (method.ReturnType != FrameworkTypes.Void)
                return false;

            
            if (method.Parameters.Count != 1)
                return false;

            // We cannot verify the parameter type since it is dynamic

            return true;
        }
    }
}
